package com.enjoy;

import com.enjoy.pojo.User;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;
import org.junit.Test;

import java.io.InputStream;
import java.sql.SQLException;
import java.util.List;

public class IBatisTest {

    public SqlMapClient getSqlMapClient() {
//        String sb = "<!DOCTYPE sqlMapConfig PUBLIC '-//iBATIS.com//DTD SQL Map Config 2.0//EN' 'http://www.iBATIS.com/dtd/sql-map-config-2.dtd'>" +
//                "<sqlMapConfig>" +
//                "<settings useStatementNamespaces='true' cacheModelsEnabled='true' enhancementEnabled='true' lazyLoadingEnabled='true'   maxRequests='150' maxSessions='64' maxTransactions='15'/>" +
//                "<transactionManager type='JDBC' commitRequired='false'>" +
//                "<dataSource type='com.alibaba.druid.support.ibatis.DruidDataSourceFactory'>" +
//                "<property name='JDBC.Driver' value=\"com.mysql.jdbc.Driver\"/>" +
//                "<property name='JDBC.ConnectionURL' value=\"jdbc:mysql://10.10.2.60:3306/enjoy?serverTimezone=UTC\"/>" +
//                "<property name='JDBC.Username' value=\"root\"/>" +
//                "<property name='JDBC.Password' value=\"123456\"/>" +
//                "</dataSource>" +
//                "</transactionManager>" +
//                "<sqlMap resource='com/enjoy/mapper/UserSQLMapper.xml'/>" +
//                "</sqlMapConfig>";
//        return SqlMapClientBuilder.buildSqlMapClient(new StringReader(sb));
        InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("config/sqlMapConfig.xml");
        return SqlMapClientBuilder.buildSqlMapClient(inputStream);
    }

    @Test
    public void test1() throws SQLException {
        SqlMapClient sqlMapClient = getSqlMapClient();
        List<User> list = sqlMapClient.queryForList("stuExampleMap.getAllStudent");
        System.out.println("list = " + list);
    }
}
